<template>
	<view class="items">
		<u--input
		    placeholder="请输入昵称"
		    border="surround"
		    v-model="nickname"
		  ></u--input>
		  <p style="font-size: 14px;color: #666;margin-top: 12px;">请输入14个字以内的中文、英文或字母。</p>
		  <view class="btn" style="margin-top: 20px;">
				<u-button type="primary" text="保 存" @click="submit"></u-button>
		  </view>
	</view>
</template>

<script>
	import $H from '@/common/js/request.js'
	export default {
      data() {
        return {
          nickname: ''
        }
      },
	  onLoad(opt) {
	  	 this.nickname = opt.name
	  },
      methods: {
		async submit(){
			try {
				const res = await $H.post('user/setInfo', {
					field: 'nickname',
					value: this.nickname // 用实际的昵称替换这里的占位符
				}, {
					token: true
				});
				if(res.code == 0){
					return uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}else{
					uni.navigateBack()
				}
			} catch (error) {
			
			} finally {
				
			}
		}
      }
	}
</script>

<style>
	page{
		background: #f8f8f8;
	}
</style>
<style lang="scss" scoped>
	
	.items{
		margin: 15px;
		background: #fff;
		border-radius: 15px;
		padding: 15px;
		.titles{
			font-size: 14px;
			margin-top: 5px;
		}
	}
</style>